package com.qf.springbootproject.controller;

import com.qf.springbootproject.ResultBean.JsonResult;
import com.qf.springbootproject.pojo.Student;
import com.qf.springbootproject.service.TestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@Api(tags = "测试接口文档")
public class TestController {
    private final static Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private TestService testService;

    @RequestMapping("/log")
    @ResponseBody
    public String testLog() {
        logger.debug("=====测试日志debug级别打印====");
        logger.info("======测试日志info级别打印=====");
        logger.error("=====测试日志error级别打印====");
        logger.warn("======测试日志warn级别打印=====");

        // 可以使用占位符打印出一些参数信息
        String str1 = "zs";
        String str2 = "28";
        logger.info("用户姓名：{},用户年龄：{}", str1, str2);

        return "success";
    }

    @GetMapping("/hello")
    @ResponseBody
    public String hello(){
        testService.test1();
        return "hello";
    }


    @PostMapping("/hello1")
    @ResponseBody
    public JsonResult hello1(){


        return null;
    }

    @PostMapping("/hello2")
    @ResponseBody
    public String hello2(){
//        testService.test1();
        String s = testService.test2();
        System.err.println("s="+s);

        return testService.test2();
    }

    @PostMapping("user/{id},{name}")
    @ResponseBody
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "学生id",defaultValue = "0")})
    @ApiOperation(value = "根据学生唯一标识获取学生信息")
    public String hello3(@PathVariable(value = "id",required = false) String id,@PathVariable String name){
        System.err.println(id);
        System.err.println(name);
//        throw new NullPointerException("sa");
        return "hello";
    }

    @PostMapping("/hello4")
    @ResponseBody
    public Student hello4(@RequestBody Student student){


        return student;
    }



}
